let flag = [false, false, false, false, false, false, false, false] // 标识菜单栏收缩的状态
// 事件委派 控制菜单栏的收缩

// 页面链接
let pageArr = [{
    'id': 0,
    'name': '工作台数据',
    'src': "../../html/cao_xiao_xu/Home.html",
  },
  {
    'id': 1,
    'name': '会员管理',
    'src': "../../html/li_guang_ming/vipList.html",
  },
  {
    'id': 2,
    'name': '会员等级',
    'src': "../../html/li_ting/会员等级.html",
  },
  {
    'id': 3,
    'name': '会员分组',
    'src': "../../html/li_ting/会员分组.html",
  },
  {
    'id': 4,
    'name': '团队提成',
    'src': "../../html/li_ting/会员设置.html",
  },
  {
    'id': 5,
    'name': '商品管理',
    'src': "../../html/ren_shan_qi/guabli.html",
  },
  {
    'id': 6,
    'name': '仓库管理',
    'src': "../../html/li_jing/cangkuguanli.html",
  },
  {
    'id': 7,
    'name': '商品分类管理',
    'src': "../../html/li_jing/fenleiguanli.html",
  },
  {
    'id': 8,
    'name': '商品标签管理',
    'src': "../../html/li_jing/shangpinbiaoqianguanli.html",
  },
  {
    'id': 9,
    'name': '商品品牌管理',
    'src': "../../html/li_jing/shangpinpinpaiguanli.html",
  },
  {
    'id': 10,
    'name': '库存预警',
    'src': "../../html/li_jing/kucunyujing.html",
  },
  {
    'id': 11,
    'name': '订单列表',
    'src': "../../html/jiang_xue_jiao/Order_list.html",
  },
  {
    'id': 12,
    'name': '订单清关',
    'src': "../../html/jiang_xue_jiao/Order_clearance.html",
  },
  {
    'id': 13,
    'name': '满减',
    'src': "../../html/wang_zheng_ze/Full_reduction.html",
  },
  {
    'id': 14,
    'name': '优惠券',
    'src': "../../html/wang_zheng_ze/coupons.html",
  },
  {
    'id': 15,
    'name': '资金流水',
    'src': "../../html/wu_qi/demo.html",
  },
  {
    'id': 16,
    'name': '佣金提现',
    'src': "../../html/wu_qi/withdraw.html",
  },
  {
    'id': 17,
    'name': '等级升级审核',
    'src': "../../html/wu_qi/Grade.html",
  },
  {
    'id': 18,
    'name': '等级升级佣金审核',
    'src': "../../html/wu_qi/review.html",
  },
  {
    'id': 19,
    'name': '团队佣金审核',
    'src': "../../html/wu_qi/InvitationCode.html",
  },
  {
    'id': 20,
    'name': '权限角色',
    'src': "../../html/jiang_xue_jiao/power.html",
  },

  {
    'id': 21,
    'name': '订单设置',
    'src': "../../html/cao_xiao_xu/region.html",
  },
  {
    'id': 22,
    'name': '国家管理',
    'src': "../../html/cao_xiao_xu/State.html",
  },

  {
    'id': 23,
    'name': '用户协议管理',
    'src': "../../html/cao_xiao_xu/Useragreement.html",
  }
]
// 需要登录后才能进
let userObj = JSON.parse(localStorage.getItem('userInfo'))
// 如果存在serObj.user) 这个值
if (!userObj) {
  alert('需要登录后才能进入')
  window.location.href = "../../html/gao_lu/login.html"
}
$(".user").text(userObj.user)

$(".parentmenu").on('click', '.p_menu', function () {
  if (!flag[Number($(this).attr('index'))]) {
    $(this).css('height', 'auto')
    $(this).find('.childmenu').show()
    flag[Number($(this).attr('index'))] = true
  } else {
    $(this).css('height', '40px')
    $(this).find('.childmenu').hide()
    flag[Number($(this).attr('index'))] = false
  }
})
// 给二级菜单增加单击事件
$(".childmenu").on('click', 'li', function (event) {
  let pages = $(this).text()
  let index = pageArr.findIndex(item => {
    return item.name == pages
  })
  $("#pages").prop('src', pageArr[index].src)
  event.stopPropagation()
})
// 退出登录
$(".loginUserInfo").click(function () {
  window.location.href = "../../html/gao_lu/login.html"
})